/* Includes ------------------------------------------------------------------*/
#include "es_gpio.h"
#include "rtthread.h"
#include "bsp_config.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/
#define LED1	PIN_OUT(GPIOB, 8)
/* Private variables ---------------------------------------------------------*/
static rt_thread_t thread0 = RT_NULL;
/* Private functions ---------------------------------------------------------*/
static void thread0_entry(void* parameter);

/* 需要使用的外设在此初始化 */
void peripherals_init()
{
	gpio_init(GPIOB, GPIO_Pin_8, GPIO_Mode_Out_PP);
}


/* 在 main 函数中初始化线程并开启调度 */
int main(void)
{
	thread0 =                          	/* 线程控制块指针 */
    rt_thread_create( "led1",         /* 线程名字 */
                      thread0_entry,  /* 线程入口函数 */
                      RT_NULL,        /* 线程入口函数参数 */
                      96,           /* 线程栈大小 */
                      3,              /* 线程的优先级 */
                      20);            /* 线程时间片 */
                   
    /* 启动线程，开启调度 */
   if (thread0 != RT_NULL)
        rt_thread_startup(thread0);
    else
        return -1;
		
}

/*
******************** 线程定义 ********************
*/
static void thread0_entry(void* parameter)
{	

	/* add your code here */   
	/* 无限循环，不能返回 */
	while (1)
	{
		/* 调用 rt_thread_delay 进入阻塞态，不能使用循环延时，否则会占用 CPU */
		rt_thread_delay(500);   /* 延时500个tick */
		LED1 = !LED1;
	}
		
}



#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{ 
  /* User can add his own implementation to report the file name and line number */
	rt_kprintf("Wrong parameters value: file %s on line %d\r\n", file, line); 
	
  /* Infinite loop */
  while (1)
  {
  }
}
#endif


/****END OF FILE****/
